﻿using System;

namespace EasyClientPlus
{


    using SuperSocket.ProtoBase;

    public class FixedHeaderReceiveFilter : FixedHeaderReceiveFilter<BinaryPackageInfo<Int16>>
    {
        const int HeaderLen = 4;
        const int BodyType = 2;

        public FixedHeaderReceiveFilter() : base(HeaderLen)
        {
        }

        public override BinaryPackageInfo<Int16> ResolvePackage(IBufferStream bufferStream)
        {
            byte[] bytes = new byte[bufferStream.Length - HeaderLen - BodyType];

            short type = (short)bufferStream.Skip(HeaderLen).ReadInt16(true);
            bufferStream.Read(bytes, 0, bytes.Length);
            return new BinaryPackageInfo<short>(type, bytes);
        }

        protected override int GetBodyLengthFromHeader(IBufferStream bufferStream, int length)
        { 
            int len = bufferStream.ReadInt32(true);
            return len;
         
        }
    }
}
